//
//  SetTabCellView.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/2/27.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

class SetTabCellView: TableRowView {
    
    var group:KIconGroup!
    
    var isSelect:Bool = false {
        didSet {
            let color = isSelect ? color_main108:NSColor.clear
            self.selectBg.layer?.backgroundColor = color.cgColor
            let txColor = isSelect ? color_gray(255):color_gray(0)
            self.title.textColor = txColor
            let image = isSelect ? (group.image+"_select"):group.image
            icon.image = NSImage.image(name:image!)
        }
    }
    
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
    }
    
    convenience init(group:KIconGroup) {
        self.init()
        self.group = group
        self.setupUI()
        self.loadData()
    }
    
    func loadData() {
        self.title.stringValue = group.title ?? "..."
        self.icon.image = NSImage.image(name:group.image)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUI() {
        self.addSubview(selectBg)
        selectBg.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.height.equalToSuperview().offset(-10)
            make.centerY.equalToSuperview()
        }
        
        self.addSubview(title)
        title.snp.makeConstraints { (make) in
            make.right.equalToSuperview()
            make.left.equalTo(25+25+5)
            make.centerY.equalToSuperview()
            make.height.equalTo(16)
        }
        self.addSubview(icon)
        icon.snp.makeConstraints { (make) in
            make.width.height.equalTo(25)
            make.left.equalTo(25)
            make.centerY.equalToSuperview()
        }
        
        self.addSubview(lineV)
        lineV.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.height.equalTo(0.5)
            make.left.equalTo(40)
            make.right.equalToSuperview().offset(-40)
        }
    }
    
    lazy var lineV: NSView = {
        let view = NSView.init()
        view.wantsLayer = true
        view.layer?.backgroundColor = color_gray(240).cgColor
        view.isHidden = true
        return view
    }()
    
    lazy var selectBg: NSView = {
        let view = NSView()
        view.wantsLayer = true
        view.layer?.backgroundColor = color_main140.cgColor
        view.layer?.masksToBounds = true
        view.layer?.cornerRadius = 5
        return view
    }()
    
    lazy var title: NSLabel = {
        let lab = NSLabel.label(title: "..", textColor: color_gray(80), font: NSFont.systemFont(ofSize: 13))
        return lab
    }()
    
    lazy var icon: NSImageView = {
        let imageV = NSImageView.init(image: NSImage.init(named: NSImage.Name.init("icon_setting_bacis"))!)
        return imageV
    }()
}
